package com.wuxiaoge.dao;

import com.wuxiaoge.dto.UserDto;
import com.wuxiaoge.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserRepository extends JpaRepository<User, Long> {

    @Modifying
    @Query(value = "update t_user u set u.name = :name where u.id = :userId",nativeQuery = true)
    int updateUserStatus(@Param("name") String name, @Param("userId") Long userId);

    @Query(value = "SELECT u.name, u.email FROM t_user u WHERE u.age > :age",nativeQuery = true)
    List<Object[]> find(@Param("age") Integer age);

    @Query(value = "SELECT u.name, u.email FROM t_user u WHERE u.age > :age",nativeQuery = true)
    List<UserDto> findUser(@Param("age") Integer age);

}

